Apply current module's filter to linked objects

I have a module (Module A) with DXL that, for each object, searches the object's in-linked objects for a specific attribute and finds the maximum value of that attribute for all of the in-linked objects.

There is an object-level enumeration attribute called Products.  It's multi-select.  The user will filter Module A on that attribute (simple or compound), using "includes". I want to add DXL to the above search so it includes only in-linked objects that meet the same criteria (the source modules for those in-linked objects will have the same Products attribute).

The source modules will most likely be closed.

Here's the current routine in Module A that performs the function described in the first paragraph:

real MaxP(Object o)
{
    Link l
    LinkRef lr
    ModName_ otherMod = null
    Module linkMod = null
    ModuleVersion otherVersion = null
    Object othero
    real rMax = -1.0
    real r
    string s
    string linkModName = "*"
    for lr in all(o<-linkModName) do {
        otherMod = module (sourceVersion lr)
        if (!null otherMod) {
            if ((!isDeleted otherMod) && (null data(sourceVersion lr))) {
                load((sourceVersion lr),false)
            }
        }
    }

    for l in all(o<-linkModName) do {
        otherVersion = sourceVersion l
        otherMod = module(otherVersion)
        if (null otherMod || isDeleted otherMod) continue
        othero = source l
        if (null othero) {
            load(otherVersion,false)
        }
        othero = source l
        if (null othero) continue
        if (isDeleted othero) continue
        s = probeAttr_(othero, "_P Numeric")    //returns "" if there is no such attr

        if (!null s)
        {
            r = othero."_P Numeric"
            if (r > rMax)
                rMax = r
        }
    }
    return rMax
}

I've tried to use the set function as follows:

Filter currentFilter = (Filter current())
set (otherMod, currentFilter)

Unfortunately, I can't find a way to specify the source module in a way that doesn't generate an error.

 

Thanks in advance for any help you can offer.


dpsours - Wed May 13 13:43:47 EDT 2015

Re: Apply current module's filter to linked objects
Mathias Mamsch - Mon May 25 05:16:28 EDT 2015

You approach is correct - the problem you are facing is that the filter inside the current module might not make sense for the other module and therefore yield an error. There is no easy way to suppress that error, so as long as your filter can be ensured to be valid for the other module you should be fine. Just make sure that you turn filtering on in the other module.

Note that the set(Module, Filter) functions takes a Module - so you need to load your module with load(...) first, to get the module handle and then use the Module handle to set the filter.

Regards, Mathias

 

Re: Apply current module's filter to linked objects
dpsours - Tue May 26 15:41:18 EDT 2015

Mathias Mamsch - Mon May 25 05:16:28 EDT 2015

You approach is correct - the problem you are facing is that the filter inside the current module might not make sense for the other module and therefore yield an error. There is no easy way to suppress that error, so as long as your filter can be ensured to be valid for the other module you should be fine. Just make sure that you turn filtering on in the other module.

Note that the set(Module, Filter) functions takes a Module - so you need to load your module with load(...) first, to get the module handle and then use the Module handle to set the filter.

Regards, Mathias

 

Thank you, Mathias.

As I play around with this, I run into a couple of things.

1) The filter in Module A seems to be in effect as far as the DXL script is concerned, regardless of whether I have the filter turned on in the DOORS UI.  How can I get around that?

2) Assuming the filter in Module A is valid for Module B (a tenuous assumption, I know), can I simply use the isFiltered function on othero rather than setting the filter in Module B?  So in the code above, right after

  if (isDeleted othero) continue

I would add

  if (!isFiltered othero) continue

Thanks again,

Dave

 

Re: Apply current module's filter to linked objects
llandale - Wed May 27 19:49:43 EDT 2015

dpsours - Tue May 26 15:41:18 EDT 2015

Thank you, Mathias.

As I play around with this, I run into a couple of things.

1) The filter in Module A seems to be in effect as far as the DXL script is concerned, regardless of whether I have the filter turned on in the DOORS UI.  How can I get around that?

2) Assuming the filter in Module A is valid for Module B (a tenuous assumption, I know), can I simply use the isFiltered function on othero rather than setting the filter in Module B?  So in the code above, right after

  if (isDeleted othero) continue

I would add

  if (!isFiltered othero) continue

Thanks again,

Dave

 

As MM said you need to convert your "ModName_" handle "otherMod" into a "Module mOther".  then apply the filter.,  Then as you said check if the othero is filtered.  So after "isDeleted(othero)) continue" add the following:

mOther = read(fullName(otherMod, false, true))    // declare "Module mOther" at the top
set(mOther, currentFilter)
// refresh(mOther)          // is this needed?
if (!filtered(othero)) then continue
// if (!isVisible(othero)) then continue   // my hackles say this is better than the "filtered" check.  Don't know why.

-Louie

Try to trap the "set" error, surrounding with noError() and lastError().  You could also send the "set" command to an "eval_" sub-context and ignore the error.

Re: Apply current module's filter to linked objects
dpsours - Tue Jun 02 16:17:45 EDT 2015

llandale - Wed May 27 19:49:43 EDT 2015

As MM said you need to convert your "ModName_" handle "otherMod" into a "Module mOther".  then apply the filter.,  Then as you said check if the othero is filtered.  So after "isDeleted(othero)) continue" add the following:

mOther = read(fullName(otherMod, false, true))    // declare "Module mOther" at the top
set(mOther, currentFilter)
// refresh(mOther)          // is this needed?
if (!filtered(othero)) then continue
// if (!isVisible(othero)) then continue   // my hackles say this is better than the "filtered" check.  Don't know why.

-Louie

Try to trap the "set" error, surrounding with noError() and lastError().  You could also send the "set" command to an "eval_" sub-context and ignore the error.

Thank you Louie.

I'm still coming back to my two questions above, however:

1) The filter in Module A seems to be in effect as far as the DXL script is concerned, regardless of whether I have the filter turned on in the DOORS UI.  How can I get around that?  So the following code will print the filter that I set through the DOORS UI, even though I turned filtering off using the "funnel" button.

    Filter currentFilter = (Filter current())

    if (!null currentFilter)
        if (getAttributeFilterSettings_(m,
                                        currentFilter,
                                        attrName,
                                        compType,
                                        compValue,
                                        mc,
                                        ure))
    s= stringOf(m,currentFilter)
    print s "\n"

 

2) There appears to be no need to set the filter in Module B.  I can simply use the isFiltered function on othero.  This certainly makes things easier, but I'm afraid there must be some catch.


I'm really stuck, so I hope you can help, particularly with #1.

Thanks,

Dave

Re: Apply current module's filter to linked objects
llandale - Tue Jun 02 20:18:44 EDT 2015

dpsours - Tue Jun 02 16:17:45 EDT 2015

Thank you Louie.

I'm still coming back to my two questions above, however:

1) The filter in Module A seems to be in effect as far as the DXL script is concerned, regardless of whether I have the filter turned on in the DOORS UI.  How can I get around that?  So the following code will print the filter that I set through the DOORS UI, even though I turned filtering off using the "funnel" button.

    Filter currentFilter = (Filter current())

    if (!null currentFilter)
        if (getAttributeFilterSettings_(m,
                                        currentFilter,
                                        attrName,
                                        compType,
                                        compValue,
                                        mc,
                                        ure))
    s= stringOf(m,currentFilter)
    print s "\n"

 

2) There appears to be no need to set the filter in Module B.  I can simply use the isFiltered function on othero.  This certainly makes things easier, but I'm afraid there must be some catch.


I'm really stuck, so I hope you can help, particularly with #1.

Thanks,

Dave

[1] If you define a filter for a module then there is a filter for that module; that filter can be on or off.  So if you need to presume that when filtering is off for any reason, then there is "no filter", then do the following:

  • current = m
  • currentFiIter = (Filter current())
  • if (!filtering(m)) then no filter for A
  • elseif (null current Filter) then no filter for A
  • else do what you want with currentFilter.

[2] If I understand your original problem, then yes you DO need to set the filter on B (if there is one active for A); and THEN check if is "isFiltered".  I wonder if you then need to set B current and turn "filtering(on)"?

-Louie

Setting the same Filter in B as exists in A does not feel right at all to me.  But if they are doppleganger modules (have the same attributes) then I suppose it is OK.

Re: Apply current module's filter to linked objects
dpsours - Wed Jun 03 11:48:44 EDT 2015

llandale - Tue Jun 02 20:18:44 EDT 2015

[1] If you define a filter for a module then there is a filter for that module; that filter can be on or off.  So if you need to presume that when filtering is off for any reason, then there is "no filter", then do the following:

  • current = m
  • currentFiIter = (Filter current())
  • if (!filtering(m)) then no filter for A
  • elseif (null current Filter) then no filter for A
  • else do what you want with currentFilter.

[2] If I understand your original problem, then yes you DO need to set the filter on B (if there is one active for A); and THEN check if is "isFiltered".  I wonder if you then need to set B current and turn "filtering(on)"?

-Louie

Setting the same Filter in B as exists in A does not feel right at all to me.  But if they are doppleganger modules (have the same attributes) then I suppose it is OK.

That's what I needed.  Thanks, guys!

Re: Apply current module's filter to linked objects
llandale - Wed Jun 03 15:45:32 EDT 2015

llandale - Tue Jun 02 20:18:44 EDT 2015

[1] If you define a filter for a module then there is a filter for that module; that filter can be on or off.  So if you need to presume that when filtering is off for any reason, then there is "no filter", then do the following:

  • current = m
  • currentFiIter = (Filter current())
  • if (!filtering(m)) then no filter for A
  • elseif (null current Filter) then no filter for A
  • else do what you want with currentFilter.

[2] If I understand your original problem, then yes you DO need to set the filter on B (if there is one active for A); and THEN check if is "isFiltered".  I wonder if you then need to set B current and turn "filtering(on)"?

-Louie

Setting the same Filter in B as exists in A does not feel right at all to me.  But if they are doppleganger modules (have the same attributes) then I suppose it is OK.

I see there are 4 states for a module vis-a-vis filtering:

  1. There is a filter defined and it is ON
  2. There is a filter defined   and it is OFF
  3. There is NO filter defined and it is ON
  4. There is NO filter defined and it is OFF

3 and 4 look alike in the GUI,  but in DXL "bool b = filtering(mod)" tells a difference.  I see no practical difference between 3 and 4, other than to confuse folks.

-Louie